import BaseUtil from "solar/util/BaseUtil";
import TextTagUtil from "solar/util/TextTagUtil";

export default class AddGoldOnUseAbilityState {

    static config: {
        [id: string]: {
            min: number,//最小获得金币
            max: number,//最大获得金币
            timeRate?: number//游戏时间（分钟）增幅比例
        }
    } = {}


    static action(this: void) {
        let configData = AddGoldOnUseAbilityState.config[id2string(GetSpellAbilityId())]
        if (!configData) {
            return
        }

        let add_gold = GetRandomInt(configData.min, configData.max);
        if (configData.timeRate && configData.timeRate > 0) {
            let timeAdd = R2I(BaseUtil.getGameTime() / 60) * configData.min
            add_gold = timeAdd * configData.timeRate + add_gold;
        }

        AdjustPlayerStateBJ(add_gold, GetOwningPlayer(GetTriggerUnit()), PLAYER_STATE_RESOURCE_GOLD);
        // 文本
        TextTagUtil.text(" +" + add_gold, GetTriggerUnit(), 15, 3, 250, 204, 64)

    }

    constructor() {
        let triggerHandle = CreateTrigger();
        TriggerRegisterAnyUnitEventBJ(triggerHandle, EVENT_PLAYER_UNIT_SPELL_EFFECT);
        TriggerAddAction(triggerHandle, AddGoldOnUseAbilityState.action);
    }
}

